package com.company.algo.Greedy;

import java.util.Arrays;

/**
 * 674. 最长连续递增序列
 */
public class FindLengthOfLCIS {
    //dp[i]=1, dp[i] = dp[i-1]+1 if nums[i]>nums[i-1]
    public int findLengthOfLCIS_DP(int[] nums) {
        int[] dp = new int[nums.length];
        Arrays.fill(dp,1);
        int maxLen = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i]>nums[i-1]) dp[i] = dp[i-1]+1;
            maxLen = Math.max(maxLen,dp[i]);
        }
        System.out.println(Arrays.toString(dp));
        return maxLen;
    }

    //记录最大值
    public int findLengthOfLCIS_Greedy(int[] nums) {
        int start = 1;
        int maxLen = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i]<=nums[i-1]) start = i;
            maxLen = Math.max(maxLen,i-start+1);
        }
        return maxLen;
    }

    public static void main(String[] args) {
        FindLengthOfLCIS Main = new FindLengthOfLCIS();
        int[] nums = {1,3,5,4,7};
        System.out.println(Main.findLengthOfLCIS_DP(nums));
        System.out.println(Main.findLengthOfLCIS_Greedy(nums));
    }
}
